/*
 * Created by JFormDesigner on Mon Aug 13 20:41:32 EDT 2007
 */

package org.timeticker.gui;

import java.util.*;
import org.timeticker.Project;

import java.awt.*;
import java.awt.event.ActionEvent;
import javax.swing.*;
import javax.swing.border.*;

/**
 * Project dialog
 *
 * @author Ivan Latysh
 * @version 0.1
 * @since 13-Aug-2007 : 20:51:43 PM
 */
public class ProjectDialog extends JDialog {

  /** Project */
  private Project project;
  /** Dialog action */
  private String action = "cancel";

  /**
   * Return project
   *
   * @return project
   */
  public Project getProject() {
    return project;
  }

  /**
   * Return dialog result action
   *
   * @return <tt>ok</tt> when user click Ok btn; <tt>cancel</tt> otherwise.
   */
  public String getAction() {
    return action;
  }


  public ProjectDialog(Frame owner, Project project) {
		super(owner);
    this.project = project;
    initComponents();
	}

	public ProjectDialog(Dialog owner, Project project) {
		super(owner);
    this.project = project;
    initComponents();
	}

  private void initComponents() {
		// JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
		// Generated using JFormDesigner Evaluation license - Ivan Latysh
		ResourceBundle bundle = ResourceBundle.getBundle("org.timeticker.timeticker");
		dialogPane = new JPanel();
		contentPanel = new JPanel();
		label1 = new JLabel();
		title = new JTextField();
		label2 = new JLabel();
		scrollPane1 = new JScrollPane();
		comments = new JTextArea();
		buttonBar = new JPanel();
		okButton = new JButton(okAction);
		cancelButton = new JButton(cancelAction);
		okAction = new OkAction();
		cancelAction = new CancelAction();

		//======== this ========
		setModal(true);
		setTitle(bundle.getString("ProjectDialog.Title"));
		Container contentPane = getContentPane();
		contentPane.setLayout(new BorderLayout());

		//======== dialogPane ========
		{
			dialogPane.setBorder(new EmptyBorder(12, 12, 12, 12));

			// JFormDesigner evaluation mark
			dialogPane.setBorder(new javax.swing.border.CompoundBorder(
				new javax.swing.border.TitledBorder(new javax.swing.border.EmptyBorder(0, 0, 0, 0),
					"JFormDesigner Evaluation", javax.swing.border.TitledBorder.CENTER,
					javax.swing.border.TitledBorder.BOTTOM, new java.awt.Font("Dialog", java.awt.Font.BOLD, 12),
					java.awt.Color.red), dialogPane.getBorder())); dialogPane.addPropertyChangeListener(new java.beans.PropertyChangeListener(){public void propertyChange(java.beans.PropertyChangeEvent e){if("border".equals(e.getPropertyName()))throw new RuntimeException();}});

			dialogPane.setLayout(new BorderLayout());

			//======== contentPanel ========
			{
				contentPanel.setLayout(new GridBagLayout());
				((GridBagLayout)contentPanel.getLayout()).columnWidths = new int[] {69, 230};
				((GridBagLayout)contentPanel.getLayout()).rowHeights = new int[] {0, 72};
				((GridBagLayout)contentPanel.getLayout()).columnWeights = new double[] {0.0, 1.0};
				((GridBagLayout)contentPanel.getLayout()).rowWeights = new double[] {0.0, 1.0};

				//---- label1 ----
				label1.setText(bundle.getString("Project.Title.Title"));
				contentPanel.add(label1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
					GridBagConstraints.CENTER, GridBagConstraints.BOTH,
					new Insets(0, 0, 5, 5), 0, 0));

				//---- title ----
				title.setText(project.getTitle());
				contentPanel.add(title, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
					GridBagConstraints.CENTER, GridBagConstraints.BOTH,
					new Insets(0, 0, 5, 0), 0, 0));

				//---- label2 ----
				label2.setText(bundle.getString("Project.Comments.Title"));
				contentPanel.add(label2, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,
					GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
					new Insets(0, 0, 0, 5), 0, 0));

				//======== scrollPane1 ========
				{

					//---- comments ----
					comments.setText(project.getComments());
					scrollPane1.setViewportView(comments);
				}
				contentPanel.add(scrollPane1, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0,
					GridBagConstraints.CENTER, GridBagConstraints.BOTH,
					new Insets(0, 0, 0, 0), 0, 0));
			}
			dialogPane.add(contentPanel, BorderLayout.CENTER);

			//======== buttonBar ========
			{
				buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0));
				buttonBar.setLayout(new GridBagLayout());
				((GridBagLayout)buttonBar.getLayout()).columnWidths = new int[] {0, 85, 80};
				((GridBagLayout)buttonBar.getLayout()).columnWeights = new double[] {1.0, 0.0, 0.0};

				//---- okButton ----
				okButton.setText(bundle.getString("Ok"));
				okButton.setAction(okAction);
				buttonBar.add(okButton, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
					GridBagConstraints.CENTER, GridBagConstraints.BOTH,
					new Insets(0, 0, 0, 5), 0, 0));

				//---- cancelButton ----
				cancelButton.setText(bundle.getString("Cancel"));
				cancelButton.setAction(cancelAction);
				buttonBar.add(cancelButton, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0,
					GridBagConstraints.CENTER, GridBagConstraints.BOTH,
					new Insets(0, 0, 0, 0), 0, 0));
			}
			dialogPane.add(buttonBar, BorderLayout.SOUTH);
		}
		contentPane.add(dialogPane, BorderLayout.CENTER);
		pack();
		setLocationRelativeTo(getOwner());
		// JFormDesigner - End of component initialization  //GEN-END:initComponents
	}

	// JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
	// Generated using JFormDesigner Evaluation license - Ivan Latysh
	private JPanel dialogPane;
	private JPanel contentPanel;
	private JLabel label1;
	private JTextField title;
	private JLabel label2;
	private JScrollPane scrollPane1;
	private JTextArea comments;
	private JPanel buttonBar;
	private JButton okButton;
	private JButton cancelButton;
	private OkAction okAction;
	private CancelAction cancelAction;
	// JFormDesigner - End of variables declaration  //GEN-END:variables

	private class CancelAction extends AbstractAction {
		private CancelAction() {
			// JFormDesigner - Action initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
			// Generated using JFormDesigner Evaluation license - Ivan Latysh
			ResourceBundle bundle = ResourceBundle.getBundle("org.timeticker.timeticker");

			putValue(NAME, bundle.getString("Cancel"));
			// JFormDesigner - End of action initialization  //GEN-END:initComponents
		}

		public void actionPerformed(ActionEvent e) {
			ProjectDialog.this.setVisible(false);
		}
	}

	private class OkAction extends AbstractAction {
		private OkAction() {
			// JFormDesigner - Action initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
			// Generated using JFormDesigner Evaluation license - Ivan Latysh
			ResourceBundle bundle = ResourceBundle.getBundle("org.timeticker.timeticker");

			putValue(NAME, bundle.getString("Ok"));
			putValue("SwingSelectedKey", false);
			// JFormDesigner - End of action initialization  //GEN-END:initComponents
		}

		public void actionPerformed(ActionEvent e) {
      // update project bean
      project.setTitle(title.getText());
      project.setComments(comments.getText());
      // update action
      action = "ok";
      // hide dialog
      ProjectDialog.this.setVisible(false);			
		}
	}
}
